//
//  FeatherView.m
//  NewGame
//
//  Created by wwj on 15/10/13.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "FeatherView.h"

@interface FeatherView ()
@property (weak ,nonatomic) IBOutlet NSLayoutConstraint *margeX;

@property (strong, nonatomic) NSTimer *timer;
@end

@implementation FeatherView

-(void)begin{
    self.alpha = 0;
}

-(void)attackWithIndex:(int)index{
    
    self.alpha = 1;
    
    CGFloat width = ([UIScreen mainScreen].bounds.size.width / 3) * (index +0.5);
    _margeX.constant = width;
    [UIView animateWithDuration:0.1 animations:^{
        [self.superview layoutIfNeeded];
        
        CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation"];
        
        CGMutablePathRef path = CGPathCreateMutable();
        
        CGFloat pathW = 30;
        CGFloat pathH = 20;
        CGFloat pathX = -pathW*0.5;
        CGFloat pathY = -pathH*0.5;
        
        CGPathAddEllipseInRect(path, NULL, CGRectMake(pathX, pathY, pathW, pathH));
        
        animation.path = path;
        [self.layer addAnimation:animation forKey:nil];
    }];
    
    [_timer invalidate];
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(hidden) userInfo:nil repeats:NO];
}

-(void)hidden{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    }];
}

@end
